<template>
  <div class="login">
    <div class="login_box">
      <img src="@/assets/img/积云.png" alt="" />
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item prop="username">
          <el-input
            v-model="ruleForm.username"
            prefix-icon="iconfont icon-user"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="ruleForm.password"
            show-password
            prefix-icon="iconfont icon-Password"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {LoginApi} from '@/http/api'
export default {
  data() {
    return {
      ruleForm: {
        username: "admin",
        password: "123456",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 6, message: "长度在 3 到 6 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 6, message: "长度在 3 到 6 个字符", trigger: "blur" },
        ],
      },
    };
  },
  components: {},
  mounted() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
           LoginApi(this.ruleForm).then(res=>{
               console.log(res);
           })

        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
  computed: {},
  watch: {},
};
</script>

<style scoped lang="scss">
@import "@/mixin/index.scss";
.login {
  width: 100%;
  height: 100%;
  background-color: aqua;
}
.login_box {
  width: 500px;
  height: 300px;
  background-color: #fff;
  border-radius: 10px;
  @include xy-center;
  box-sizing: border-box;
  padding: 20px;
  text-align: right;
  img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    position: absolute;
    top: -40px;
    left: 215px;
  }
  .demo-ruleForm {
    margin-top: 50px;
  }
}
</style>
